home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / aros / devs / console.c < prev    next >
C/C++ Source or Header  |  1996-09-12  |  5KB  |  201 lines

  1. /*
  2.     (C) 1995-96 AROS - The Amiga Replacement OS
  3.     $Id: console.c,v 1.2 1996/09/11 16:54:19 digulla Exp $
  4.     $Log: console.c,v $
  5.     Revision 1.2  1996/09/11 16:54:19  digulla
  6.     Always use __AROS_SLIB_ENTRY() to access shared external symbols, because
  7.         some systems name an external symbol "x" as "_x" and others as "x".
  8.         (The problem arises with assembler symbols which might differ)
  9.  
  10.     Revision 1.1  1996/08/23 17:32:23  digulla
  11.     Implementation of the console.device
  12.  
  13.  
  14.     Desc:
  15.     Lang:
  16. */
  17. #include <exec/resident.h>
  18. #include <devices/inputevent.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/console_protos.h>
  21. #include <aros/libcall.h>
  22. #ifdef __GNUC__
  23. #    include "console_gcc.h"
  24. #endif
  25.  
  26. static const char name[];
  27. static const char version[];
  28. static const APTR inittabl[4];
  29. static void *const functable[];
  30. static const UBYTE datatable;
  31.  
  32. struct consolebase *__AROS_SLIB_ENTRY(init,Console)();
  33. void __AROS_SLIB_ENTRY(open,Console)();
  34. BPTR __AROS_SLIB_ENTRY(close,Console)();
  35. BPTR __AROS_SLIB_ENTRY(expunge,Console)();
  36. int __AROS_SLIB_ENTRY(null,Console)();
  37. void __AROS_SLIB_ENTRY(beginio,Console)();
  38. LONG __AROS_SLIB_ENTRY(abortio,Console)();
  39.  
  40. extern struct InputEvent * __AROS_SLIB_ENTRY(CDInputHandler,Console) ();
  41. extern LONG __AROS_SLIB_ENTRY(RawKeyConvert,Console) ();
  42. static const char end;
  43.  
  44. int __AROS_SLIB_ENTRY(entry,Console)(void)
  45. {
  46.     /* If the device was executed by accident return error code. */
  47.     return -1;
  48. }
  49.  
  50. const struct Resident Console_resident=
  51. {
  52.     RTC_MATCHWORD,
  53.     (struct Resident *)&Console_resident,
  54.     (APTR)&end,
  55.     RTF_AUTOINIT,
  56.     1,
  57.     NT_LIBRARY,
  58.     0,
  59.     (char *)name,
  60.     (char *)&version[6],
  61.     (ULONG *)inittabl
  62. };
  63.  
  64. static const char name[]="console.device";
  65.  
  66. static const char version[]="$VER: console 1.0 (23.8.96)\n\015";
  67.  
  68. static const APTR inittabl[4]=
  69. {
  70.     (APTR)sizeof(struct consolebase),
  71.     (APTR)functable,
  72.     (APTR)&datatable,
  73.     &__AROS_SLIB_ENTRY(init,Console)
  74. };
  75.  
  76. static void *const functable[]=
  77. {
  78.     &__AROS_SLIB_ENTRY(open,Console),
  79.     &__AROS_SLIB_ENTRY(close,Console),
  80.     &__AROS_SLIB_ENTRY(expunge,Console),
  81.     &__AROS_SLIB_ENTRY(null,Console),
  82.     &__AROS_SLIB_ENTRY(beginio,Console),
  83.     &__AROS_SLIB_ENTRY(abortio,Console),
  84.     &__AROS_SLIB_ENTRY(CDInputHandler,Console),
  85.     &__AROS_SLIB_ENTRY(RawKeyConvert,Console),
  86.     (void *)-1
  87. };
  88.  
  89. __AROS_LH2(struct consolebase *, init,
  90.  __AROS_LHA(struct consolebase *, consoleDevice, D0),
  91.  __AROS_LHA(BPTR,              segList,   A0),
  92.        struct ExecBase *, sysBase, 0, Console)
  93. {
  94.     __AROS_FUNC_INIT
  95.  
  96.     /* Store arguments */
  97.     consoleDevice->sysBase = sysBase;
  98.     consoleDevice->seglist = segList;
  99.  
  100.     consoleDevice->device.dd_Library.lib_OpenCnt=1;
  101.  
  102.     return consoleDevice;
  103.     __AROS_FUNC_EXIT
  104. }
  105.  
  106. __AROS_LH3(void, open,
  107.  __AROS_LHA(struct IORequest *, ioreq, A1),
  108.  __AROS_LHA(ULONG,              unitnum, D0),
  109.  __AROS_LHA(ULONG,              flags, D0),
  110.        struct consolebase *, ConsoleDevice, 1, Console)
  111. {
  112.     __AROS_FUNC_INIT
  113.  
  114.     /* Keep compiler happy */
  115.     unitnum=0;
  116.     flags=0;
  117.  
  118.     /* I have one more opener. */
  119.     ConsoleDevice->device.dd_Library.lib_Flags&=~LIBF_DELEXP;
  120.  
  121.     __AROS_FUNC_EXIT
  122. }
  123.  
  124. __AROS_LH1(BPTR, close,
  125.  __AROS_LHA(struct IORequest *, ioreq, A1),
  126.        struct consolebase *, ConsoleDevice, 2, Console)
  127. {
  128.     __AROS_FUNC_INIT
  129.  
  130.     /* Let any following attemps to use the device crash hard. */
  131.     ioreq->io_Device=(struct Device *)-1;
  132.     return 0;
  133.     __AROS_FUNC_EXIT
  134. }
  135.  
  136. __AROS_LH0(BPTR, expunge, struct consolebase *, ConsoleDevice, 3, Console)
  137. {
  138.     __AROS_FUNC_INIT
  139.  
  140.     /* Do not expunge the device. Set the delayed expunge flag and return. */
  141.     ConsoleDevice->device.dd_Library.lib_Flags|=LIBF_DELEXP;
  142.     return 0;
  143.     __AROS_FUNC_EXIT
  144. }
  145.  
  146. __AROS_LH0I(int, null, struct consolebase *, ConsoleDevice, 4, Console)
  147. {
  148.     __AROS_FUNC_INIT
  149.     return 0;
  150.     __AROS_FUNC_EXIT
  151. }
  152.  
  153. __AROS_LH1(void, beginio,
  154.  __AROS_LHA(struct IORequest *, ioreq, A1),
  155.        struct consolebase *, ConsoleDevice, 5, Console)
  156. {
  157.     __AROS_FUNC_INIT
  158.     LONG error=0;
  159.  
  160.     /* WaitIO will look into this */
  161.     ioreq->io_Message.mn_Node.ln_Type=NT_MESSAGE;
  162.  
  163.     /*
  164.     Do everything quick no matter what. This is possible
  165.     because I never need to Wait().
  166.     */
  167.     switch (ioreq->io_Command)
  168.     {
  169.     default:
  170.     error=ERROR_NOT_IMPLEMENTED;
  171.     break;
  172.     }
  173.  
  174.     /* If the quick bit is not set send the message to the port */
  175.     if(!(ioreq->io_Flags&IOF_QUICK))
  176.     ReplyMsg (&ioreq->io_Message);
  177.  
  178.     /* Trigger a rescedule every now and then */
  179.     if(SysBase->TaskReady.lh_Head->ln_Pri==SysBase->ThisTask->tc_Node.ln_Pri&&
  180.        SysBase->TDNestCnt<0&&SysBase->IDNestCnt<0)
  181.     {
  182.     SysBase->ThisTask->tc_State=TS_READY;
  183.     Enqueue(&SysBase->TaskReady,&SysBase->ThisTask->tc_Node);
  184.     Switch();
  185.     }
  186.  
  187.     __AROS_FUNC_EXIT
  188. }
  189.  
  190. __AROS_LH1(LONG, abortio,
  191.  __AROS_LHA(struct IORequest *, ioreq, A1),
  192.        struct consolebase *, ConsoleDevice, 6, Console)
  193. {
  194.     __AROS_FUNC_INIT
  195.     /* Everything already done. */
  196.     return 0;
  197.     __AROS_FUNC_EXIT
  198. }
  199.  
  200. static const char end=0;
  201.